package com.boge.tools;

import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;
import dev.langchain4j.service.Result;

public class MainDemo2 {
    public static void main(String[] args) {
        String apiKey = System.getenv("AI-BAILIAN-API-KEY");
        OpenAiChatModel model = OpenAiChatModel.builder()
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .apiKey(apiKey)
                .modelName("deepseek-r1")
                .logRequests(true)
                .logResponses(true)
                .build();


        Assistant assistant = AiServices.builder(Assistant.class)
                .chatModel(model)
                .tools(new WeatherTools())
                .chatMemory(MessageWindowChatMemory.withMaxMessages(10))
                .build();

        String question = "北京明天的天气怎么样?";

        Result<String> chat = assistant.chat(question);
        System.out.println(chat.finalResponse().aiMessage().text());
    }
}

interface Assistant {

    Result<String> chat(String userMessage);
}
